package com.boot.security.server.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boot.security.server.annotation.UserOnly;
import com.boot.security.server.model.Role;

import io.swagger.annotations.Api;

@Api(tags = "hello")
@RestController
@RequestMapping("/demo")
public class HelloController {
	
	private final Logger log=LoggerFactory.getLogger(getClass());
	@GetMapping("/reqCategorys")
	public List<Role> reqCategorys() {
		List<Role>roles=new ArrayList<Role>();
		for (int i = 0; i < 10; i++) {
			Role role=new Role();
			role.setName("role"+i);
			role.setDescription("description"+i);
			role.setCreateTime(new Date());
			role.setUpdateTime(new Date());
			roles.add(role);
		}
		return roles;
	}
	
	@UserOnly
	@GetMapping("/hello")
	public String hello(String userId,String name) {
		log.info(userId);
		return "Hello "+name;
	}
	
	@UserOnly
	@PostMapping("/hello")
	public String hello1(String userId,String name) {
		log.info(userId);
		return "Hello "+name;
	}

}
